package nongchang.kuaijiecaifu.com.ncapp_android.util.validator;

import android.support.annotation.NonNull;
import android.widget.TextView;


import com.mobsandgeeks.saripaar.annotation.NotEmpty;
import com.mobsandgeeks.saripaar.annotation.Order;
import com.mobsandgeeks.saripaar.annotation.Pattern;

import nongchang.kuaijiecaifu.com.ncapp_android.Const;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.API;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.base.Response;
import nongchang.kuaijiecaifu.com.ncapp_android.util.Helpers;
import rx.Observable;

public class PhoneValidator extends DefaultValidator {

    @Order(1)
    @NotEmpty(message = "手机号不能为空")
    @Pattern(regex = Const.REGEX_PHONE,message = "请输入正确的手机号")
    private TextView txtPhone;

    private String mRule = "exists";

    public PhoneValidator(@NonNull TextView phone) {
        txtPhone = phone;
        init(this);
    }
    public PhoneValidator(@NonNull TextView phone, String rule) {
        txtPhone = phone;
        mRule = rule;
        init(this);
    }


    public <R>  DefaultValidator succeeded(Observable.Transformer<? super Response, ? extends R> transformer) {
        return super.succeeded(() -> {
//            API.main.smsSend(mRule, txtPhone.getText().toString())
//                       .compose(transformer)
//                       .subscribe(result -> {
//                           Helpers.countdown((TextView)mClicked);
//                       });
        });
    }
}